<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <h1>当前的n值是：<span v-text="n"></span></h1>
        <h1>放大10倍后的n值是：<span v-big-number="n"></span></h1>
        <button @click="n++">点我n++</button>
        <hr>
        <input type="text" v-fbind:value="n">
    </div>
    <script>
        Vue.config.productionTip = false //取消生产提示

        // Vue.directive('fbind', { //全局指令
        //     bind(element, binding) {
        //         console.log('bind');
        //         element.value = binding.value
        //     },
        //     inserted(element, binding) {
        //         console.log('inserted');
        //         element.focus()
        //     },
        //     update(element, binding) {
        //         console.log('update');
        //         element.value = binding.value
        //         element.focus()
        //     },
        // })
        // Vue.directive('big-number', function (element, binding) {
        //     element.innerHTML = binding.value * 10
        // })
        const vm = new Vue({
            el: '#root',
            data() {
                return {
                    n: 1
                }
            },
            directives: { //里面的this指向都是window
                //函数式 相当于只写了bind和update
                'big-number'(element, binding) {
                    element.innerHTML = binding.value * 10
                    // console.log(element, binding);
                },
                //对象式
                fbind: {
                    // inserted(element, binding) {
                    //     element.value = binding.value
                    //     element.focus()
                    // }

                    bind(element, binding) {
                        console.log('bind');
                        element.value = binding.value
                    },
                    inserted(element, binding) {
                        console.log('inserted');
                        element.focus()
                    },
                    update(element, binding) {
                        console.log('update');
                        element.value = binding.value
                        // element.focus()
                    },
                }
            }
        })
    </script>
</body>

</html>